# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=regex
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=2020.4.4
pkgrel=1
pkgdesc="Alternative python regular expression module. (mingw-w64)"
arch=('any')
url='https://www.regex.org/'
license=('Python')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
options=('staticlibs' 'strip' '!debug')
source=("https://files.pythonhosted.org/packages/source/r/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('295badf61a51add2d428a46b8580309c520d8b26e769868b922750cf3ce67142')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  cd "${srcdir}/${_realname}-${pkgver}"
  ${MINGW_PREFIX}/bin/python -c 'from regex.test.test_regex import test_main; test_main()'
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  sed -n '1,/^$/p' regex_2/regex.py > LICENSE
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"

  install -v -m755 -d "${pkgdir}${MINGW_PREFIX}/share/doc/python-regex"
  install -v -m644 docs/Features.html "${pkgdir}${MINGW_PREFIX}/share/doc/python-regex/"
  install -v -m644 docs/Features.rst "${pkgdir}${MINGW_PREFIX}/share/doc/python-regex/"
  install -v -m644 docs/UnicodeProperties.rst "${pkgdir}${MINGW_PREFIX}/share/doc/python-regex/"
}
